package com.zzh.dialog;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;

import com.zzh.FillBlankActivity;
import com.zzh.dialog.databinding.ActivityMainBinding;
import com.zzh.dialog.image.Image1Activity;
import com.zzh.dialog.typer.TyperActivity;
import com.zzh.lib.core.listener.HOnClickListener;
import com.zzh.lib.core.utils.HTaskUtils;
import com.zzh.lib.dialog.AlertDialog;
import com.zzh.lib.dialog.DialogConfirmView;
import com.zzh.lib.dialog.DialogMenuView;
import com.zzh.lib.dialog.Dialoger;
import com.zzh.lib.dialog.animator.AlphaCreator;
import com.zzh.lib.dialog.impl.HDialogConfirmView;
import com.zzh.lib.dialog.impl.HDialogMenuView;
import com.zzh.lib.dialog.load.LoadingDialog;
import com.zzh.lib.snackbar.HSnackbar;
import com.zzh.lib.snackbar.HTopTips;
import com.zzh.lib.xpopup.XPopup;
import com.zzh.lib.xpopup.impl.ConfirmPopupView;
import com.zzh.lib.xpopup.interfaces.OnCancelListener;
import com.zzh.lib.xpopup.interfaces.OnConfirmListener;
import com.zzh.tab.ui.SimpleHomeActivity;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    static Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.btnTyperEffect.setOnClickListener(new HOnClickListener() {
            @Override
            public void onSafeClick(View v) {
                startActivity(new Intent(MainActivity.this, TyperActivity.class));
            }
        });
        binding.mbTime.setOnClickListener(v -> {
            startActivity(new Intent(MainActivity.this, TimeActivity.class));
        });
        binding.tvImage2.setOnClickListener(v -> startActivity(new Intent(this, Image1Activity.class)));
        binding.mbSticky.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, StickRecyclerActivity.class)));

        binding.mbFillBlank.setOnClickListener(v -> startActivity(new Intent(this, FillBlankActivity.class)));

        binding.btnLoading.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                XPopup.loadDialog(MainActivity.this, "加载中").showText(false);
                HTaskUtils.getDefaultInstance().execute(() -> runOnUiThread(XPopup::dismissSuccess), 2000);
            }
        });

        binding.btnSheetDialogSuccess.setOnClickListener(v -> {
            HTopTips.showTopSuccess(this, "成功");
        });

        binding.btnSheetDialogError.setOnClickListener(v -> {
            HTopTips.showTopError(this, "错误");
        });

        binding.btnSheetDialogWarn.setOnClickListener(v -> {
            HTopTips.showTopWarn(this, "警告");
        });
        binding.btnSheetDialogNormal.setOnClickListener(v -> {
            HTopTips.show(this, "这是一个普通的不能再普通的信息了");
        });

        binding.btnSheetDialog.setOnClickListener(v -> {
            HSnackbar.makeShortTopTips(this, "访问数据成功").setCallback(new HSnackbar.Callback() {
                @Override
                public void onDismissed(HSnackbar TSnackbar, int event) {
                    super.onDismissed(TSnackbar, event);
                }
            }).addIcon(R.drawable.ic_launcher_background).show();
        });
        binding.btnDialogTime.setOnClickListener(v -> startActivity(new Intent(this, com.zzh.dialog.picker.MainActivity.class)));
        binding.btnAlertDialogShow.setOnClickListener(v -> AlertDialog.show(MainActivity.this, null, "这是提示信息"));
    }

    ShowDialog dialog;

    public void onClickView(View v) {
        if (dialog == null) {
            dialog = new ShowDialog(this);
            dialog.setAnimatorCreator(new AlphaCreator());
        }
        if (dialog.isShowing()) {
            dialog.dismiss();
        } else {
            dialog.show();
        }
    }

    public void onClickView11(View v) {
        startActivity(new Intent(this, com.zzh.dialog.xpop.MainActivity.class));
    }

    public void onClickView1(View v) {
        HDialogConfirmView view = new HDialogConfirmView(this);
        Dialoger dialoger = view.getDialoger();
        dialoger.show();
        view.setCallback(new DialogConfirmView.Callback() {
            @Override
            public void onClickCancel(View v, DialogConfirmView view) {
                super.onClickCancel(v, view);
                Log.e("-----", "cancel");
            }

            @Override
            public void onClickConfirm(View v, DialogConfirmView view) {
                super.onClickConfirm(v, view);
                Log.e("-----", "onClickConfirm");
            }
        });

    }

    public void onClickView4(View v) {
        AlertDialog.show(this, "标题", "提示内容内容", new OnConfirmListener() {
            @Override
            public void onConfirm() {

            }
        });

    }

    public void onClickView5(View v) {
        ConfirmPopupView show = AlertDialog.show(this, "标题", "提示内容内容", new OnConfirmListener() {
            @Override
            public void onConfirm() {

            }
        }, new OnCancelListener() {
            @Override
            public void onCancel() {

            }
        });

    }

    public void onClickView2(View v) {
        LoadingDialog dialog = new LoadingDialog(this);
        dialog.setShowTime(3000);
        dialog.show();
        handler.postDelayed(() -> {
//            dialog.loadSuccess();
            dialog.close();
        }, 3000);
    }

    public void onClickView3(View v) {
        HDialogMenuView view = new HDialogMenuView(this);
        view.setItems("一", "二", "伞");
        Dialoger dialoger = view.getDialoger();
        dialoger.show();
        view.setCallback(new DialogMenuView.Callback() {
            @Override
            public void onClickItem(View v, int index, DialogMenuView view) {
                super.onClickItem(v, index, view);
            }

            @Override
            public void onClickCancel(View v, DialogMenuView view) {
                super.onClickCancel(v, view);
            }
        });
    }


    public void onClickTabSimple(View view) {
        startActivity(new Intent(this, SimpleHomeActivity.class));
    }
}
